package userInterface.tool;

import javax.swing.*;
import java.awt.*;

import static java.lang.Thread.sleep;

public class Pointer extends JLabel {
    private Rectangle rectangle;
    private Point point;
    /*
    * 见Bar的变量解释
    * */
    public Pointer(Rectangle rectangle){
        super();
        ImageIcon img=new ImageIcon("source/pointer.png");
        img.setImage(img.getImage().getScaledInstance(rectangle.width,rectangle.height,Image.SCALE_DEFAULT));
        setIcon(img);//使图标自适应安排的label区域

        point=rectangle.getLocation();
        this.rectangle=rectangle;
        setBounds(rectangle);
    }
    public void movX(Point destination) throws InterruptedException {
        //todo
            if (point.x<destination.x) {
                while (point.x<destination.x) {
                    point.x++;
                    rectangle.x++;
                    this.setBounds(rectangle);
                    sleep(1);
                }
            }
            if (point.x>destination.x){
                while (point.x>destination.x) {
                    point.x--;
                    rectangle.x--;
                    this.setBounds(rectangle);
                    sleep(1);
                }
            }
        }


    public Rectangle getRectangle() {
        return rectangle;
    }

    public Point getPoint() {
        return point;
    }

}
